// $codepro.audit.disable logExceptions
/*
 * Copyright (c) 2011 Team A CS2340. All rights reserved.
 */


package edu.gatech.teama.doctorsoffice.client.presenter;

import java.util.List;

import javax.swing.JTextArea;
import javax.swing.JTextField;

import edu.gatech.teama.doctorsoffice.model.TreatmentRecord;
import edu.gatech.teama.doctorsoffice.model.TreatmentsTable;
/**
 * TreatmentRecordPresenter.java
 * @author Emily Rice
 * @version 1.0
 */
public class TreatmentRecordPresenter { // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.alwaysOverridetoString.alwaysOverrideToString
	
	/**
	 * treatment record
	 */
	private final TreatmentRecord tr;
	
	/**
	 * treatment record presenter constructor
	 * @param tr the treatmentRecord of this patient
	 */
	public TreatmentRecordPresenter(TreatmentRecord tr){
		this.tr = tr;
		
	}
	
	/**
	 * user lookup presenter constructor
	 * @param diagnosis
	 * @param complaint
	 * @param sBlood
	 * @param dBlood
	 * @param temp
	 * @param pulse
	 * @param height
	 * @param lbs
	 */

	public void save(JTextArea diagnosis, JTextArea complaint, JTextField sBlood,  // $codepro.audit.disable largeNumberOfParameters
			JTextField dBlood, JTextField temp, 
			JTextField pulse, JTextField height, JTextField lbs){
		tr.setDiagnosis(diagnosis.getText());
		tr.setSymptoms(complaint.getText());
		
		int newSBlood;
		try {
			newSBlood = Integer.parseInt(sBlood.getText());
		} catch(java.lang.NumberFormatException e) {
			newSBlood = tr.getVitalSigns().getBloodPressureSystolic();
		}
		tr.getVitalSigns().setBloodPressureSystolic(newSBlood);

		int newDBlood;
		try {
			newDBlood = Integer.parseInt(dBlood.getText());
		} catch(java.lang.NumberFormatException e) {
			newDBlood = tr.getVitalSigns().getBloodPressureDiastolic();
		}
		tr.getVitalSigns().setBloodPressureDiastolic(newDBlood);
		
		double newTemp;
		try {
			newTemp = Double.parseDouble(temp.getText());
		} catch(java.lang.NumberFormatException e) {
			newTemp = tr.getVitalSigns().getBodyTemperature();
		}
	    tr.getVitalSigns().setBodyTemperature(newTemp);
		
	    int newPulse;
		try {
			newPulse = Integer.parseInt(pulse.getText());
		} catch(java.lang.NumberFormatException e) {
			newPulse = tr.getVitalSigns().getPulse();
		}
		tr.getVitalSigns().setPulse(newPulse);
		
		double newHeight;
		try {
			newHeight = Double.parseDouble(height.getText());
		} catch(java.lang.NumberFormatException e) {
			newHeight = tr.getVitalSigns().getHeightInches();
		}
		tr.getVitalSigns().setHeightInches(newHeight);
		
		double newWeight;
		try {
			newWeight = Double.parseDouble(lbs.getText());
		} catch(java.lang.NumberFormatException e) {
			newWeight = tr.getVitalSigns().getWeightLbs();
		}
		tr.getVitalSigns().setWeight(newWeight);
	}
	
	/**
	 * saves treatments
	 * @param list the list from the view
	 */
	public void saveTreatments(List<String> list){
		for(String s :list){
			tr.addTreatments(s);
		}
	}
	
	/**
	 * Adds a treatment to the treatment record
	 * @param treatmentSelection
	 */
	public void addTreatment(String treatmentSelection) {
		final String treatmentName =
			TreatmentsTable.getMatchingTreatmentName(treatmentSelection);
		if (treatmentName != null) {
			tr.getTreatments().add(treatmentName);
		}
	}

	/**
	 * Removes a treatment from the treatment record
	 * @param treatmentName
	 */
	public void removeTreatment(String treatmentName) {
		tr.getTreatments().remove(treatmentName);
	}
}
